<!--头部公共部分-->
{include file="common/header" /}
<div class="x-nav">
      <span class="layui-breadcrumb">
        <a>首页</a>
        <a>管理</a>
        <a>
          <cite>转介绍管理</cite></a>
      </span>
    <a class="layui-btn layui-btn-xs layui-btn-small" style="float:right;margin-top: 10px;"
       href="javascript:location.replace(location.href);" title="刷新">
        <i class="layui-icon layui-icon-refresh"></i> </a>
</div>
<div class="x-body">
    <div class="layui-row">
        <div class="layui-form layui-col-md12 x-so layui-form-pane">
            <div class="layui-input-inline"  style="width: 100px;">
                <select name="stype">
                    <option value="">学员姓名</option>
                    <option value="2">学员手机</option>
                    <option value="3">家长姓名</option>
                    <option value="4">家长手机</option>
                </select>
            </div>
            <div class="layui-input-inline">
                <input type="text" name="keywords" placeholder="请输入搜索关键词" autocomplete="off" class="layui-input">
            </div>
            <div class="layui-input-inline">
                <select name="user_id" lay-search="" lay-filter="user_id">
                    <option value="">请选择课程顾问</option>
                    {volist name="users" id="user"}
                    <option value="{$user.id}">{$user['name']}</option>
                    {/volist}
                </select>
            </div>
            <div class="layui-input-inline">
                <input type="text" name="day" id="date" placeholder="日期" autocomplete="off" class="layui-input">
            </div>
            <div class="layui-input-inline">
                <select name="channel" lay-search="" lay-filter="channel">
                    <option value="">请选择来源</option>
                    {volist name="data[2]" id="v"}
                    <option value="{$v.id}">{$v['name']}</option>
                    {/volist}
                </select>
            </div>
            <div class="layui-input-inline">
                <button class="layui-btn" id="search">
                    <i class="layui-icon layui-icon-search"></i>筛选</button>
                <button class="layui-btn layui-btn-danger" id="clear">
                    <i class="layui-icon"></i>重置</button>
            </div>
        </div>
    </div>
</div>
<blockquote id="kehuguanli" class="layui-elem-quote">
    转介绍管理
</blockquote>
<table class="layui-table" id="datalist" lay-filter="Event"></table>
<script type="text/html" id="barTable">
    {{# if(d.sign_up == 1){ }}
    <a class="layui-btn layui-btn-xs layui-btn-disabled" >报名</a>
    {{# } else { }}
    <a class="layui-btn layui-btn-xs layui-btn-normal" lay-event="sign_up">报名</a>
    {{# } }}
</script>
</div>
<!--底部公共部分-->
{include file="common/footer" /}
<script>
    layui.use(['table','laydate','element', 'layer'], function () {
        let table = layui.table,
            laydate = layui.laydate,
            element = layui.element,
            layer = layui.layer,
            $ = layui.$;

        //限定可选日期
        laydate.render({
            elem: '#date'
            // ,max: day_date
            ,range: true
            ,trigger: 'click'
        });
        let loading = layer.load();
        //方法级渲染
        let tableIns = table.render({
            elem: '#datalist'
            , url: '{:url("Administration/customer_new_introduce")}'
            , method: 'POST'
            , loading: true
            , parseData: function (res) { //res 即为原始返回的数据
                if (res.code === 1) {
                    res.code = 0;
                } else {
                    res.code = -1;
                }
                return {
                    "code": res.code, //解析接口状态
                    "msg": res.message, //解析提示文本
                    "count": res.data.total, //解析数据长度
                    "data": res.data.data //解析数据列表
                };
            },
            cols: [[
                {field: 'name', title: '姓名',style:'color:#01AAED;font-weight: bold;', align: 'center', templet: '#name'},
                {field: 'phone', title: '联系方式', align: 'center'},
                {field: 'channel', title: '来源', align: 'center'},
                {field: 'course_consultant', title: '课程顾问', align: 'center', sort: true},
                {field: 'introduction', title: '介绍人', align: 'center'},
                {field: 'follow_up_text', title: '跟进状态', align: 'center'},
                {field: 'intentional_grade_text', title: '意向级别', align: 'center', sort: true},
                {field: 'register_date', title: '登记日期', align: 'center', sort: true},
                {title: '操作', fixed: 'right', align: 'center', toolbar: '#barTable'},
            ]]
            , page: true
            , done: function () {
                layer.close(loading);
            }
        });
        //监听工具条
        table.on('tool(Event)', function (obj) {
            let data = obj.data; //获得当前行数据
            let layEvent = obj.event; //获得 lay-event 对应的值
            if (layEvent === 'sign_up') {
                //报名
                location.href = '{:url("Customer/course_contract")}?student_id=' + data.id  +'&campus_id=33' +'&type=4';
            }
        });

        //搜索项
        $('#search').click(function () {
            let field = {};
            field.stype = $('select[name=stype] option:selected').val();
            field.follow_up = $('select[name=follow_up] option:selected').val();
            field.channel = $('select[name=channel] option:selected').val();
            field.user_id = $('select[name=user_id] option:selected').val();
            field.day = $('input[name=day]').val();
            field.keywords = $('input[name=keywords]').val();
            tableIns.reload({
                where: field,
                method: 'POST',
                page: {
                    curr: 1 //重新从第 1 页开始
                }
            });
        });
        //清除
        $('#clear').click(function () {
            $('.layui-input').each(function (index, element) {
                $(element).val('');
            })
            tableIns.reload({
                where: {
                    'keywords': '',
                    'follow_up': '',
                    'channel': '',
                    'user_id': '',
                    'day': ''
                },
                page: {
                    curr: 1 //重新从第 1 页开始
                }
            });
        });
    });
</script>